<template>
	<view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:{
					identity:{
						member_level:''
					}
				}
			}
		},
		onLoad(options) {
				let roleType = '';
				let userInfo = uni.getStorageSync('userInfo');
				if(!userInfo){
					this.getUserInfo();
				}else{
					this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
				}
				roleType = this.userInfo.identity.member_level;
				if( roleType == 'user' || !roleType){
					uni.showModal({
						title: '提示',
						content: '没有权限访问',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url:'/pages/index/index'
								});
							} else {
								console.log('点击了取消')
							}
						}
					})
				}else{
					uni.redirectTo({
						url:'/pages/diy/diy?page_id=168'
					})
				}
		},
		methods: {
			async getUserInfo(){
				let res = await this.$http.request({
					url: this.$api.user.userInfo,
					method: 'POST',
					showLoading: true
				});
				if (res.code == 0) {
					this.userInfo = res.data;
					uni.setStorageSync('userInfo', JSON.stringify(res.data));
				} else {
					uni.removeStorageSync('userInfo');
				}
			}
		}
	}
</script>

<style>

</style>
